using ASP;
using HoWave.Common;
using HoWave.Web;
using HoWave.Web.Shop.Member;
using System;
using System.Data;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Xml;
public class Shop_Member_Shop_AddDeliver : Member, IRequiresSessionState
{
	protected string defaultstyle = "";
	public int m_UserID = 0;
	protected HtmlHead Head1;
	protected HiddenField deliverID;
	protected HiddenField action;
	protected TextBox deliver_project_name;
	protected Literal hasOrdinary;
	protected Literal ordpost_update;
	protected Literal hasCorpFast;
	protected Literal corpfast_update;
	protected Literal hasPostFast;
	protected Literal postfast_update;
	protected Literal hasEms;
	protected Literal ems_update;
	protected TextBox deliver_msg;
	protected HtmlForm savePostageForm;
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		SysLabel sysLabel = new SysLabel(this.conn);
		this.defaultstyle = sysLabel.GetDefaultIndexCss("Member");
		this.conn.CloseConn();
		this.m_UserID = base.user.UserID;
		if (!base.IsPostBack)
		{
			this.GetData();
		}
		else
		{
			this.SetData();
		}
	}
	protected void GetData()
	{
		string text = string.Concat(new string[]
		{
			"<ol id=\"postFastItems\" prefix=\"postFast\"><li id=\"defaultPostFastItem\" style=\"background:#F3FEED;\">",
			Language.GetMemberMsg("Deliver/SetFreight", new string[0]),
			"<input type=\"text\" id=\"defaultPostFastFee\" name=\"postfast_default\" {0} size=\"6\" maxlength=\"6\" class=\"required validate-float-range-0.01-999.99\" title=\"",
			Language.GetMemberMsg("Deliver/LargeFreight", new string[0]),
			"\"/>",
			Language.Get("Compare/Yuan"),
			",&nbsp;&nbsp;&nbsp;&nbsp;",
			Language.GetMemberMsg("Deliver/OneFreight", new string[0]),
			"<input type=\"text\" id=\"defaultPostFastIncrement\" name=\"postfast_increment\" {1} size=\"6\" maxlength=\"6\" value=\"0.0\"  title='",
			Language.GetMemberMsg("Deliver/SmallFreight", new string[0]),
			"'/>",
			Language.Get("Compare/Yuan"),
			"</li></ol>"
		});
		string text2 = string.Concat(new string[]
		{
			"<ol id=\"ordItems\" prefix=\"ord\"><li id=\"defaultOrdItem\" style=\"background:#F3FEED;\">",
			Language.GetMemberMsg("Deliver/SetFreight", new string[0]),
			"<input type=\"text\" id=\"defaultOrdFee\" name=\"ordpost_default\" {0} size=\"6\" maxlength=\"6\"  title=\"",
			Language.GetMemberMsg("Deliver/LargeFreight", new string[0]),
			"\"/>",
			Language.Get("Compare/Yuan"),
			",&nbsp;&nbsp;&nbsp;&nbsp;",
			Language.GetMemberMsg("Deliver/OneFreight", new string[0]),
			"<input type=\"text\" id=\"defaultOrdIncrement\" name=\"ordpost_increment\" {1} size=\"6\" maxlength=\"6\" value=\"0.0\" title='",
			Language.GetMemberMsg("Deliver/SmallFreight", new string[0]),
			"'/>",
			Language.Get("Compare/Yuan"),
			"</li></ol>"
		});
		string text3 = string.Concat(new string[]
		{
			"<ol id=\"corpFastItems\" prefix=\"corpFast\"><li id=\"defaultCorpFastItem\" style=\"background:#F3FEED;\">",
			Language.GetMemberMsg("Deliver/SetFreight", new string[0]),
			"<input type=\"text\" id=\"defaultCorpFastFee\" name=\"corpfast_default\" {0} size=\"6\" maxlength=\"6\"  title=\"",
			Language.GetMemberMsg("Deliver/LargeFreight", new string[0]),
			"\"/>",
			Language.Get("Compare/Yuan"),
			",&nbsp;&nbsp;&nbsp;&nbsp;",
			Language.GetMemberMsg("Deliver/OneFreight", new string[0]),
			"<input type=\"text\" id=\"defaultCorpFastIncrement\" name=\"corpfast_increment\" {1} size=\"6\" maxlength=\"6\" value=\"0.0\" title='",
			Language.GetMemberMsg("Deliver/SmallFreight", new string[0]),
			"'/>",
			Language.Get("Compare/Yuan"),
			"</li></ol>"
		});
		string text4 = string.Concat(new string[]
		{
			"<ol id=\"emsItems\" prefix=\"ems\"><li id=\"defaultEmsItem\" style=\"background:#F3FEED;\">",
			Language.GetMemberMsg("Deliver/SetFreight", new string[0]),
			"<input type=\"text\" id=\"defaultEmsFee\" name=\"ems_default\" {0} size=\"6\" maxlength=\"6\"  title=\"",
			Language.GetMemberMsg("Deliver/LargeFreight", new string[0]),
			"\"/>",
			Language.Get("Compare/Yuan"),
			"，&nbsp;&nbsp;&nbsp;&nbsp;",
			Language.GetMemberMsg("Deliver/OneFreight", new string[0]),
			"<input type=\"text\" id=\"defaultEmsIncrement\" name=\"ems_default_increment\" {1} size=\"6\" maxlength=\"6\" value=\"0.0\" title='",
			Language.GetMemberMsg("Deliver/SmallFreight", new string[0]),
			"'/>",
			Language.Get("Compare/Yuan"),
			"</li></ol>"
		});
		bool flag = true;
		string format = "<input id=\"hasOrdinary\" name=\"has_ordinary\" type=\"checkbox\" value=\"true\" {0} onclick=\"displayArea(this, _$('ordArea'))\" />";
		string format2 = "<input id=\"hasPostFast\" name=\"has_post_fast\" type=\"checkbox\" value=\"true\" {0} onclick=\"displayArea(this, _$('postFastArea'))\" />";
		string format3 = "<input id=\"hasCorpFast\" name=\"has_corp_fast\" type=\"checkbox\" value=\"true\" {0} onclick=\"displayArea(this, _$('corpFastArea'))\" />";
		string format4 = "<input id=\"hasEms\" name=\"has_ems\" type=\"checkbox\" value=\"true\" {0} onclick=\"displayArea(this, _$('emsArea'))\" />";
		if (base.Request["action"] != null && base.Request["action"] != "")
		{
			if (base.Request["action"] == "save" && base.Request["DeliverID"] != null && base.Request["DeliverID"] != "")
			{
				int num = int.Parse(base.Request["DeliverID"]);
				Shop_DeliverType shop_DeliverType = new Shop_DeliverType();
				DataTable deliverTypeByUserIDTypeID = shop_DeliverType.GetDeliverTypeByUserIDTypeID(this.m_UserID, base.Request["DeliverID"]);
				if (deliverTypeByUserIDTypeID != null && deliverTypeByUserIDTypeID.Rows.Count > 0)
				{
					this.deliver_project_name.Text = deliverTypeByUserIDTypeID.Rows[0]["TypeName"].ToString();
					this.deliver_msg.Text = deliverTypeByUserIDTypeID.Rows[0]["Intro"].ToString();
					string text5 = deliverTypeByUserIDTypeID.Rows[0]["DeliverAraa"].ToString();
					if (text5 != "")
					{
						XmlDocument xmlDocument = new XmlDocument();
						xmlDocument.LoadXml(text5);
						XmlNode xmlNode = xmlDocument.SelectSingleNode("root/project/deliver[@name=\"平邮\"]");
						XmlNode xmlNode2 = xmlDocument.SelectSingleNode("root/project/deliver[@name=\"邮政快递\"]");
						XmlNode xmlNode3 = xmlDocument.SelectSingleNode("root/project/deliver[@name=\"其它快递\"]");
						XmlNode xmlNode4 = xmlDocument.SelectSingleNode("root/project/deliver[@name=\"EMS\"]");
						text4 = this.BindDataToPage(text4, xmlNode4, "emsItems", "emsPrefix");
						text3 = this.BindDataToPage(text3, xmlNode3, "corpFastItems", "corpFastPrefix");
						text2 = this.BindDataToPage(text2, xmlNode, "ordItems", "ordPrefix");
						text = this.BindDataToPage(text, xmlNode2, "postFastItems", "postFastPrefix");
						flag = false;
						if (xmlNode != null)
						{
							this.hasOrdinary.Text = string.Format(format, "checked");
						}
						if (xmlNode2 != null)
						{
							this.hasPostFast.Text = string.Format(format2, "checked");
						}
						if (xmlNode3 != null)
						{
							this.hasCorpFast.Text = string.Format(format3, "checked");
						}
						if (xmlNode4 != null)
						{
							this.hasEms.Text = string.Format(format4, "checked");
						}
					}
				}
			}
		}
		if (flag)
		{
			text4 = string.Format(text4, "", "");
			text3 = string.Format(text3, "", "");
			text2 = string.Format(text2, "", "");
			text = string.Format(text, "", "");
		}
		this.ordpost_update.Text = text2;
		this.postfast_update.Text = text;
		this.ems_update.Text = text4;
		this.corpfast_update.Text = text3;
		if (string.IsNullOrEmpty(this.hasOrdinary.Text))
		{
			this.hasOrdinary.Text = string.Format(format, "");
		}
		if (string.IsNullOrEmpty(this.hasPostFast.Text))
		{
			this.hasPostFast.Text = string.Format(format2, "");
		}
		if (string.IsNullOrEmpty(this.hasCorpFast.Text))
		{
			this.hasCorpFast.Text = string.Format(format3, "");
		}
		if (string.IsNullOrEmpty(this.hasEms.Text))
		{
			this.hasEms.Text = string.Format(format4, "");
		}
	}
	protected string BindDataToPage(string ReplaceStr, XmlNode xn, string ItemType, string ItemPrefix)
	{
		if (xn != null)
		{
			ReplaceStr = string.Format(ReplaceStr, "value=\"" + xn.Attributes["default"].Value + "\"", "value=\"" + xn.Attributes["defIncrement"].Value + "\"");
			if (xn.HasChildNodes)
			{
				XmlNodeList xmlNodeList = xn.SelectNodes("item");
				ReplaceStr = ReplaceStr + "<script type=\"text/javascript\">" + Environment.NewLine;
				foreach (XmlNode xmlNode in xmlNodeList)
				{
					string text = ReplaceStr;
					ReplaceStr = string.Concat(new string[]
					{
						text,
						"window.setTimeout(\"createPostageItem(_$('",
						ItemType,
						"'), '",
						xmlNode.SelectSingleNode("area").InnerXml,
						"', '",
						xmlNode.SelectSingleNode("price").InnerXml,
						"', '",
						xmlNode.SelectSingleNode("increment").InnerXml,
						"', ",
						ItemPrefix,
						");\", timeout)",
						Environment.NewLine
					});
				}
				ReplaceStr = ReplaceStr + "</script>" + Environment.NewLine;
			}
		}
		else
		{
			ReplaceStr = string.Format(ReplaceStr, "", "");
		}
		return ReplaceStr;
	}
	protected void SetData()
	{
		if (base.Request["action"] != null)
		{
			Shop_DeliverType shop_DeliverType = new Shop_DeliverType();
			string text = base.Request["action"];
			if (text != null)
			{
				if (!(text == "add"))
				{
					if (text == "save")
					{
						if (base.Request["DeliverID"] != null && base.Request["DeliverID"] != "")
						{
							int typeID = int.Parse(base.Request["DeliverID"]);
							shop_DeliverType.UpDateDeliverType(typeID, false, base.Request["deliver_project_name"], 0m, 0, base.Request["deliver_msg"]);
						}
					}
				}
				else
				{
					if (!shop_DeliverType.CheckSalerDeliverTypeLimit(4, this.m_UserID))
					{
						this.Page.ClientScript.RegisterStartupScript(this.Page.GetType(), "alert", "<script>alert(\"" + Language.GetMemberMsg("Deliver/NotDe", new string[0]) + "\");</script>");
						return;
					}
					shop_DeliverType.InsertDeliverType(false, base.Request["deliver_project_name"], 0m, 0, base.Request["deliver_msg"], this.m_UserID, true);
					if (base.Request["from"] == "publish")
					{
						string text2 = string.Concat(new string[]
						{
							"<span id='CheckBoxList_DeliverType'><input id='CheckBoxList_DeliverType_0' type='radio' name='CheckBoxList_DeliverType'  /><label for='CheckBoxList_DeliverType_0'>",
							base.Request["deliver_project_name"],
							"</label></span><input type='hidden' name='chk_deliver_type' value='",
							base.Request["deliver_project_name"],
							"'/>"
						});
						this.Page.ClientScript.RegisterStartupScript(this.Page.GetType(), "alert", "<script>alert('" + Language.GetAdminMsg("Common/AddSuccess") + "');window.close();window.location.href='../Add_Products.aspx';</script>");
						return;
					}
				}
			}
			base.Response.Redirect("Shop_DeliverType.aspx");
		}
	}
}
